<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>模板</title>
</head>

<body>
  <div id="app">
    
    

    


    <router-view></router-view>
  </div>
  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
  <script>
    // 定义组件
    let Login = {
      // 在组件模板上不用加this
      template: `<h1>我是登录组件</h1>`
    }
    let Register = {
      // template: `<h1>我是注册组件{{$route.params.username}}</h1>`
      template: `<h1>我是注册组件{{$route.query.username}}</h1>`
    }

    // 定义路由列表
    let routes = [{
        path: '/login',
        name: 'login',
        component: Login
      },
      {
        path: '/register',
        name: 'register',
        component: Register
      }
    ]

    // 定义路由器
    let router = new VueRouter({
      routes
    })

    // 创建Vue实例
    let vm = new Vue({
      el: '#app',
      data: {

      },
      methods: {
        doRedirect(str) {
          // this.$router.push('/' + str)
          this.$router.push({
            name:'str',
            // params:{id:1001,username:'王五'}
            query:{id:1001,username:'王五'}
          })
        }
      },
      router
    })
  </script>
</body>

</html>